//A.显示右边弹出层
function stretchLayerShow(w)
{
    if( ! w){ w = 800; }
    var obj = $('.stretch_layer');
    obj.css({ 'width':w });
    obj.animate({'right':'0'}, 200);
    $('.CRM-stretch-layer').animate({'right':'0'}, 200);
    $("body").css({"overflow-y":"hidden"});
}
//B.隐藏右边弹出层
function stretchLayerHide()
{
    var obj = $('.stretch_layer');
    if(obj.length){//是否存在元素
        var w = obj.width()+20;
        var p_right = obj.css('right');
        p_right = parseInt(p_right);
        if(p_right > -1){
            $("body").css({"overflow-y":"auto"});
            obj.animate({'right':-w}, 200);
            $('#s_layer_content').html('');//清空一下，避免元素冲突
        }
    }
}
//C.右边弹层操作
function stretchLayer(opt)
{
    var op = $.extend({
        title : '标题',
        content : '内容',
        width : 800,
        content_type : 'ajax',
        url : '',
        request_type: 'get',
        request_async : false
    },opt);

    $('#s_layer_title').html(op.title);

    if(op.content_type == 'ajax'){
        $.ajax({
            url : op.url,
            beforeSend : function(){$('#s_layer_content').html('<div style="text-align:center; margin-top:10px;"><img src="/js/libs/stretchLayer/loading.gif" /></div>');},
            type : op.request_type,
            async : op.request_async,
            dataType : 'html',
            success : function(msg){
                $('#s_layer_content').html(msg);
                stretchLayerShow(op.width);
            },
            error : function(){
                $('#s_layer_content').html('加载失败:(');
            }
        });
    }else{
        $('#s_layer_content').html('需要扩展其他类型');
    }

    // if($(".stretch_layer").length){//是否存在元素
    // var p_right = $(".stretch_layer").css('right');
    // p_right = parseInt(p_right);
    //if(p_right < 0){
    //   stretchLayerShow();
    //}
    //console.log('here');
    //$('#s_layer_content').mCustomScrollbar({scrollInertia:2, theme:'dark'});
    //}
}